#include<iostream>
#include<fstream>
#include<cmath>

using namespace std;

int main()
{
    int beta = 2, p = 3, L = -1, U = 1;
    ofstream fout1, fout2;

    // Calculate the UFL and OFL.
    fout1.open("dataB1.txt", ios::out);
    fout2.open("dataB2.txt", ios::out);
    double UFL = pow(beta, L);
    double OFL = pow(beta, U) * (beta - pow(beta, 1 - p));
    fout1 << "UFL(F) is : " << UFL << endl;
    fout1 << "OFL(F) is : " << OFL << endl;

    // Calculate the cardinality.
    double m, x;
    int card = 0, e = 0;
    for (e = L; e <= U; e++)
    {
        m = 1;
        for (int i = 0; i < pow(beta,p-1)-1; i++)
        {
            x = m * pow(beta,e);
            fout2 << x << " " << -x << " ";
            card += 2;

            m += pow(beta, 1-p);
        }
        x = pow(m,e);
        fout2 << x << " " << -x << " ";
        card += 2;
    }
    fout2 << 0 << endl;
    card += 1;
    fout1 << "The cardinality of F is : " << card << endl;

    // Calculate the subnormal FPNs
    m = 0;
    double t = pow(beta, L);
    for (int i = 0; i < pow(beta,p-1)-1; i++)
    {
        m += pow(beta, 1-p);
        x = m * t;
        fout2 << x << " " << -x << " ";
    }
    fout2 << endl;

    fout1.close();
    fout2.close();
    cout << "Finish calculating." << endl;
    return 0;
}